package com.lg.controller;

import com.lg.pojo.Person;
import com.lg.service.PersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/lgperson")
@Slf4j
public class PersonController {

    @Autowired
    private PersonService personService;

    @PostMapping(value = "/createNewPerson")
    private String createNewPerson(@RequestBody Person person) {
        if (personService.createNewPerson(person)) {
            return "Create new person success！";
        }
        return "Create new person failed！";
    }

    @RequestMapping(value = "/selectPersonByName")
    private Person selectPersonByName(@RequestParam("name") String name) {
        return personService.selectPersonByName(name);
    }

    @PostMapping(value = "/updatePerson")
    private String updatePerson(@RequestBody Person person) {
        if (personService.updatePerson(person)) {
            return "Update person success!";
        }
        return "Update person failed!";
    }

    @RequestMapping(value = "/deletePerson")
    private String deletePerson(@RequestParam("id") Long id) {
        if (personService.deletePerson(id)) {
            return "Delete person success!";
        }
        return "Delete person failed!";
    }

}
